<?php

namespace app\admin\model\yxerp;

use think\Model;

/**
 * Employee
 */
class Employee extends Model
{
    // 表名
    protected $name = 'yxerp_employee';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 显示部门和岗位字段
    protected $append = ['department_name', 'position_name'];

    public function getDepartmentNameAttr()
    {
        return $this->department_id ? \app\admin\model\yxerp\Department::where('id', $this->department_id)->value('name') : null;
    }

    public function getPositionNameAttr()
    {
        return $this->position_id ? \app\admin\model\yxerp\Position::where('id', $this->position_id)->value('name') : null;
    }


    public function admin(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\Admin::class, 'admin_id', 'id');
    }
}